import { FormSchema } from '@/components/Form'; //DailyStatistics {
import { h } from 'vue';
import { DataTableCreateSummary } from 'naive-ui';
//DailyStatistics {
// 		Id          uint64  `json:"id"`
// 		Date        string  `json:"date"`        // 日期
// 		Cost        float64 `json:"cost"`        // 消耗
// 		UnitPrice   float64 `json:"unitPrice"`   // 单价
// 		FirstDayRoi float64 `json:"firstDayRoi"` // 首日ROI
// 		BeforRoi    float64 `json:"beforRoi"`    // 分成前ROI
// 		AfterRoi    float64 `json:"afterRoi"`    // 分成后ROI
// 		RegistNum   uint64  `json:"registNum"`   // 新注册
// 		RoleNum     uint64  `json:"roleNum"`     // 新角色
// 		PayNum      uint64  `json:"payNum"`      // 新增付费用户
// 		PayAmount   float64 `json:"payAmount"`   // 新增付费额
// 		PayCost     float64 `json:"payCost"`     // 新增付费成本
// 		PayRate     float64 `json:"payRate"`     // 新增付费率
// 		Arpu        float64 `json:"arpu"`        // 新增ARPU
// 		Arppu       float64 `json:"arppu"`       // 新增ARPPU
// 		CreateTime  string  `json:"createTime"`
// 		UpdateTime  string  `json:"updateTime"`
//
// 		ActivePeople  uint64  `json:"activePeople"`  //总活跃用户数
// 		TotalPayNum   uint64  `json:"totalPayNum"`   //总付费用户数
// 		TotalRecharge float64 `json:"totalRecharge"` //总充值金额
// 		ActivePayRate float64 `json:"activePayRate"` //活跃付费率
// 		ActiveArpu    float64 `json:"activeArpu"`     //活跃arpu
// 		ActiveArppu   float64 `json:"activeArppu"`    //活跃arppu
// 	}

export interface RowData {
  date: string;
  cost: number;
  unitPrice: number;
  firstDayRoi: number;
  beforRoi: number;
  afterRoi: number;
  registNum: number;
  roleNum: number;
  payNum: number;
  payAmount: number;
  payCost: number;
  payRate: number;
  arpu: number;
  arppu: number;
  todayRecharge: number;
  activePeople: number;
  totalPayNum: number;
  totalRecharge: number;
  activePayRate: number;
  activeArpu: number;
  activeArppu: number;
}

export const columns = [
  {
    title: '日期',
    key: 'date',
    width: 97,
  },
  {
    title: '消耗',
    key: 'cost',
    width: 100,
  },
  {
    title: '单价',
    key: 'unitPrice',
    width: 70,
  },
  {
    title: '首日ROI',
    key: 'firstDayRoi',
    width: 78,
    render(row) {
      return h(
        'span',
        { style: row.firstDayRoi > 50 ? 'color:green' : 'color:red' },
        { default: () => row.firstDayRoi + '%' }
      );
    },
  },
  {
    title: '分成前ROI',
    key: 'beforRoi',
    width: 92,
    render(row) {
      // return ((row.totalRecharge / row.cost) * 100).toFixed(2) + '%';
      return h(
        'span',
        { style: (row.totalRecharge / row.cost) * 100 > 50 ? 'color:green' : 'color:red' },
        { default: () => ((row.totalRecharge / row.cost) * 100).toFixed(2) + '%' }
      );
    },
  },
  {
    title: '分成后ROI',
    key: 'afterRoi',
    width: 92,
    render(row) {
      // return ((row.totalRecharge / row.cost) * 0.8 * 100).toFixed(2) + '%';
      return h(
        'span',
        {
          style: (row.totalRecharge / row.cost) * 0.8 * 100 > 50 ? 'color:green' : 'color:red',
        },
        { default: () => ((row.totalRecharge / row.cost) * 0.8 * 100).toFixed(2) + '%' }
      );
    },
  },
  {
    title: '新注册',
    key: 'registNum',
    width: 90,
  },
  {
    title: '新角色',
    key: 'roleNum',
    width: 90,
  },
  {
    title: '首日付费用户',
    key: 'payNum',
    width: 109,
  },
  {
    title: '首日付费额',
    key: 'payAmount',
    width: 95,
  },
  {
    title: '首日付费成本',
    key: 'payCost',
    width: 109,
  },
  {
    title: '首日付费率',
    key: 'payRate',
    width: 95,
    render(row) {
      return (row.payRate * 100).toFixed(2) + '%';
    },
  },
  {
    title: '首日ARPU',
    key: 'arpu',
    width: 95,
  },
  {
    title: '首日ARPPU',
    key: 'arppu',
    width: 105,
  },
  {
    title: '今日充值金额',
    key: 'todayRecharge',
    width: 109,
  },
  {
    title: '目前活跃人数',
    key: 'activePeople',
    width: 109,
  },
  {
    title: '总付费人数',
    key: 'totalPayNum',
    width: 95,
  },
  {
    title: '总充值金额',
    key: 'totalRecharge',
    width: 95,
  },
  {
    title: '活跃付费率',
    key: 'activePayRate',
    width: 95,
    render(row) {
      return row.activePayRate + '%';
    },
  },
  {
    title: '活跃arpu',
    key: 'activeArpu',
    width: 85,
  },
  {
    title: '活跃arppu',
    key: 'activeArppu',
    width: 89,
  },
];

export const addCloumns: FormSchema[] = [
  {
    field: 'date',
    component: 'NDatePicker',
    label: '日期',
    giProps: {
      span: 1,
    },
    componentProps: {
      type: 'date',
      placeholder: '',
    },
  },
  {
    field: 'cost',
    label: '消耗',
    component: 'NInputNumber',
    componentProps: {
      type: 'input',
      placeholder: '请输入消耗',
    },
  },
];

// @ts-ignore
export const createSummary: DataTableCreateSummary = (pageData: RowData[]) => {
  const roleNum = pageData.reduce((prevValue, row) => prevValue + row.roleNum, 0);
  const payNum = pageData.reduce((prevValue, row) => prevValue + row.payNum, 0);
  const registNum = pageData.reduce((prevValue, row) => prevValue + row.registNum, 0);
  const totalPayNum = pageData.reduce((prevValue, row) => prevValue + row.totalPayNum, 0);
  const activePeople = pageData.reduce((prevValue, row) => prevValue + row.activePeople, 0);
  const cost = pageData.reduce((prevValue, row) => prevValue + row.cost, 0);
  const payAmount = pageData.reduce((prevValue, row) => prevValue + row.payAmount, 0);
  const totalRecharge = pageData.reduce((prevValue, row) => prevValue + row.totalRecharge, 0);
  const todayRecharge = pageData.reduce((prevValue, row) => prevValue + row.todayRecharge, 0);
  return {
    date: {
      value: h('span', {}, '汇总'),
      colSpan: 1,
    },
    cost: {
      value: h('span', {}, cost.toFixed(2)),
      colSpan: 1,
    },
    unitPrice: {
      value: h('span', {}, (cost / roleNum).toFixed(2)),
      colSpan: 1,
    },
    firstDayRoi: {
      value: h(
        'span',
        { style: (payAmount / cost) * 100 > 50 ? 'color:green' : 'color:red' },
        ((payAmount / cost) * 100).toFixed(2) + '%'
      ),
      colSpan: 1,
    },
    beforRoi: {
      value: h(
        'span',
        { style: (totalRecharge / cost) * 100 > 50 ? 'color:green' : 'color:red' },
        ((totalRecharge / cost) * 100).toFixed(2) + '%'
      ),
      colSpan: 1,
    },
    afterRoi: {
      value: h(
        'span',
        { style: (totalRecharge / cost) * 0.8 * 100 > 50 ? 'color:green' : 'color:red' },
        ((totalRecharge / cost) * 0.8 * 100).toFixed(2) + '%'
      ),
      colSpan: 1,
    },
    registNum: {
      value: h('span', {}, registNum),
      colSpan: 1,
    },
    roleNum: {
      value: h('span', {}, roleNum),
      colSpan: 1,
    },
    payNum: {
      value: h('span', {}, payNum),
      colSpan: 1,
    },
    payAmount: {
      value: h('span', {}, payAmount),
      colSpan: 1,
    },
    payCost: {
      value: h('span', {}, (cost / payNum).toFixed(2)),
      colSpan: 1,
    },
    payRate: {
      value: h('span', {}, ((payNum / registNum) * 100).toFixed(2) + '%'),
      colSpan: 1,
    },
    arpu: {
      value: h('span', {}, (payAmount / roleNum).toFixed(2)),
      colSpan: 1,
    },
    arppu: {
      value: h('span', {}, (payAmount / payNum).toFixed(2)),
      colSpan: 1,
    },
    todayRecharge: {
      value: h('span', {}, todayRecharge),
      colSpan: 1,
    },
    activePeople: {
      value: h('span', {}, activePeople),
      colSpan: 1,
    },
    totalPayNum: {
      value: h('span', {}, totalPayNum),
      colSpan: 1,
    },
    totalRecharge: {
      value: h('span', {}, totalRecharge),
      colSpan: 1,
    },
    activePayRate: {
      value: h('span', {}, (activePeople > 0 ? (totalPayNum / activePeople).toFixed(2) : 0) + '%'),
      colSpan: 1,
    },
    activeArpu: {
      value: h('span', {}, activePeople > 0 ? (totalRecharge / activePeople).toFixed(2) : 0),
      colSpan: 1,
    },
    activeArppu: {
      value: h('span', {}, (totalRecharge / totalPayNum).toFixed(2)),
      colSpan: 1,
    },
  };
};
export const fromSchema = [
  {
    field: 'timeRange',
    label: '日期',
    componentProps: {
      placeholder: '日期',
    },
    slot: 'anchorSelect',
  },
];
